﻿using AutoMapper;
using EWC.HIS.Application.Contracts.AppointmentRegistrationService.Dtos;
using EWC.HIS.Application.Contracts.AppointmentRegistrationService.Queries;
using EWC.HIS.Domain;
using EWC.HIS.Domain.Entities;
using EWC.HIS.Domain.Repositories;
using MediatR;
using System.Threading;
using System.Threading.Tasks;

namespace EWC.HIS.Application.AppointmentRegistrations.Handlers
{
    public class GetAppointmentRegistrationQueryHandler : IRequestHandler<GetAppointmentRegistrationQuery, AppointmentRegistrationDto>
    {
        private readonly IMapper _mapper;
        private readonly IAppointmentRegistrationRepository _appointmentRegistrationRepository;

        public GetAppointmentRegistrationQueryHandler(IMapper mapper, IAppointmentRegistrationRepository appointmentRegistrationRepository)
        {
            _mapper = mapper;
            _appointmentRegistrationRepository = appointmentRegistrationRepository;
        }

        public async Task<AppointmentRegistrationDto> Handle(GetAppointmentRegistrationQuery request, CancellationToken cancellationToken)
        {
            var registration = await _appointmentRegistrationRepository.GetAsync(request.Id);
            return _mapper.Map<AppointmentRegistrationDto>(registration);
        }
    }
}
